<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="A fully featured admin theme which can be used to build CRM, CMS, etc.">
        <meta name="author" content="Coderthemes">

        <!-- App Favicon -->
        <link rel="shortcut icon" href="assets/images/favicon.ico">

		<link href="images/newlog.ico" rel="shortcut icon"><!-- 图标 -->
        <!-- App title -->
        <title>TopSales - All for one, one for all.</title>

        <!-- App CSS -->
        <link href="css/login/bootstrap.min.css" rel="stylesheet" type="text/css">
        <link href="css/login/core.css" rel="stylesheet" type="text/css">
        <link href="css/login/components.css" rel="stylesheet" type="text/css">
        <link href="css/login/icons.css" rel="stylesheet" type="text/css">
        <link href="css/login/pages.css" rel="stylesheet" type="text/css">
        <link href="css/login/menu.css" rel="stylesheet" type="text/css">
        <link href="css/login/responsive.css" rel="stylesheet" type="text/css">
        <link href="lib/drag/drag.css" rel="stylesheet" type="text/css">
		<link href="lib/sweetalert/dist/sweetalert.css" rel="stylesheet"><!-- 提示框 -->
    </head>
    <body onkeydown="keyUp();">
        <div class="account-pages"></div>
        <div class="clearfix"></div>
        <div class="wrapper-page">
            <div class="text-center">
                <a href="index.html" class="logo"><span>Top<span>Sales</span></span></a>
                <h5 class="text-muted m-t-0 font-600">All for one, one for all.</h5>
            </div>
        	<div class="m-t-40 card-box">
                <div class="text-center">
                    <h4 class="text-uppercase font-bold m-b-0">快捷登录</h4>
                </div>
                <div class="panel-body">
                    <form class="form-horizontal m-t-20" >

                        <div class="form-group ">
                            <div class="col-xs-12">
                                <input class="form-control" type="phone" id="mobile" required="" onkeyup="keyUp()" placeholder="输入手机">
                            </div>
                        </div>
                        
                        <div class="form-group ">
							<div class="col-xs-12">
								<div id="drag"></div>
							</div>
						</div>

                       <div class="form-group ">
							<div class="col-xs-12"style="position: relative;">
								<input class="form-control" type="text" required="" onkeyup="keyUp()" id="msgCode" placeholder="输入验证码" style="max-width:70%">
								<button onclick="getmobilecaptcha()" id="time" type="button" class="btn btn-info waves-effect w-md waves-light m-b-5" style="position: absolute;left:68%;top:0px;height:38px;">获取验证码</button>
							</div>
						</div>
                        
                        <div class="form-group">
							<div class="col-xs-12">
								<div class="checkbox checkbox-custom">
									<input id="checkbox-signup" type="checkbox" checked="checked">
									<label for="checkbox-signup">我同意 <a href="#">应用服务协议</a></label>
								</div>
							</div>
						</div>

                        <div class="form-group text-center m-t-30">
                            <div class="col-xs-12">
                                <button class="btn btn-custom btn-bordred btn-block waves-effect waves-light" type="button" onclick="shortCutLogin()">登录</button>
                            </div>
                        </div>

                        <div class="form-group m-t-30 m-b-0">
                            <div class="col-sm-12">
                            	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            	<a href="login.html" class="text-muted"><i class="fa fa-lock m-r-5"></i> 会员登录</a>&nbsp; |&nbsp;
                                <a href="recoverpw.html" class="text-muted"><i class="fa fa-lock m-r-5"></i> 忘记密码?</a>&nbsp; |&nbsp; 
								<a href="register.html" class="text-muted"><i class="fa fa-lock m-r-5"></i> 注册新账户</a> 
                            </div>
                        </div>
                    </form>

                </div>
            </div>
            <!-- end card-box-->
        </div>
        <!-- end wrapper page -->
        <script type="text/javascript" src="lib/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="lib/drag/drag.js"></script>
        <script src="lib/bootstrap/js/bootstrap.min.js"></script>
        <script src="lib/sweetalert/dist/sweetalert.min.js"></script>
        <script src="lib/sweetalert/sweet.js"></script>
       	<script src="lib/layer/layer.js"></script>   <!--layer提示框-->
        <script src="js/common/storage.com.js"></script>
        <script src="js/common.js"></script>
        <script src="js/judgeVersion.js"></script><!-- 判断浏览器版本 -->    
    	<script>
            var resizefunc = [];
            $('#drag').drag();
           	
            function keyUp(event){
	           	var e = event || window.event || arguments.callee.caller.arguments[0];
	           	if(e && e.keyCode==27){ // 按 Esc 
	           	    //要做的事情
	           	  }
	           	if(e && e.keyCode==113){ // 按 F2 
	           	     //要做的事情
	           	   }            
	           	 if(e && e.keyCode==13){ // enter 键
	           		shortCutLogin();
	           	    }
	           	}; 
	           	
            //获取验证码
            function getmobilecaptcha(){
            	
            	var serverHref;
          		if (window["context"] == undefined) {
          		    if (!window.location.origin) {
          		        window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
          		    }
          		    window["context"] = location.origin;
          		}
          		 
          	 	serverHref=window["context"];
            	var servicesUrl =serverHref+"/topsales_services/"
            	
            	if($("#dragYZ").html()=="验证通过"){
            		settime($("#time"));
            		$.ajax({
              			url : servicesUrl + "captcha/getmobilecaptcha",
              			type : 'post',
              			data : "mobileNo=" + $("#mobile").val(),
              			dataType : 'json',
              			async : true,
              			success : function(data){
              				if(data.code == 1){

              				}else{
              					sweet.auto(result.message);
              				}
              			},
              			error : function(result){
              				sweet.auto("网络错误!");
              			}
              		});
            	}else{
            		sweet.auto("请滑动验证！","error",1000);
            	}
            }
            
            var countdown = 60;
            var intime = true;
        	function settime(obj) {
        		if(countdown == 0) {
        			obj.attr("disabled", false);
        			obj.html("获取验证码");
        			intime = true;
        			countdown = 60;
        			return;
        		} else if(intime) {
        			obj.attr("disabled", true);
        			obj.html("重新发送(" + countdown + ")");
        			countdown--;
        		} else {
        			obj.attr("disabled", false);
        			obj.html("获取验证码");
        			intime = false;
        			countdown = 60;
        			return;
        		}
        		setTimeout(function() {
        			settime(obj)
        		}, 1000)
        	}
        	
        	//快捷登录
        	 function shortCutLogin(){
        		 var re = /^1[3|4|5|7|8][0-9]{9}$/;
             	if($("#mobile").val()==""){
             		sweet.auto("请填手机号!","error",1000);
             		return;
             	}else if(!re.test($("#mobile").val())){
             		sweet.auto("手机号格式错误!","error",1000);
             		return;
             	}else if($("#msgCode").val()==""){
             		sweet.auto("请填写验证码!","error",1000);
             		return;
             	}else if($("#checkbox-signup").is(":checked")==false){
            		sweet.auto("同意服务协议才能登录!","error",1000);
            		return;
            	}else{
             		var params = {
             				mobile : $("#mobile").val(),
             				msgCode : $("#msgCode").val(),
             		}
             	}
             	//测试用
           		var serverHref;
           		if (window["context"] == undefined) {
           		    if (!window.location.origin) {
           		        window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
           		    }
           		    window["context"] = location.origin;
           		}
           	 	serverHref=window["context"];
           		var servicesUrl =serverHref+"/topsales_services/";
           		var baseUrlSys =serverHref+"/WebSystem/";
           		if($("#mobile").val()==""||$("#msgCode").val()==""){//手机号、验证码、密码为空不调用接口
          			
    	      		
          		}else{
		           		$.ajax({
		           			url : servicesUrl + "login/mobilelogin",
		           			type : 'post',
		           			data : params,
		           			dataType : 'json',
		           			async : true,
		           			success : function(result){
		           				if(result.code == 1){
		           					var apiKey = result.validateMap.apiKey;
		           					var permissions = result.validateMap.permissions;
		           					myWeb.Storage.setValueSession("author", apiKey);
		           					//myWeb.Storage.setValueSession("TmsSysApiKey",apiKey);
		           					//myWeb.Storage.setValueSession("permissionList", permissions);
		           					myWeb.Storage.setValueSession("userName", result.validateMap.userName);
		           					myWeb.Storage.setValueSession("userId",result.validateMap.userId);
		           					myWeb.Storage.setValueSession("mobile",result.validateMap.mobile);
		           					//myWeb.Storage.setValueSession("companyName", result.validateMap.companyName);
		           					//myWeb.Storage.setValueSession("language", 'pagesCn');
		           					//myWeb.Storage.setValueSession("userLevel", result.validateMap.userLevel);
		                           // myWeb.Storage.setValueSession("companyId", result.validateMap.companyId);
		           					window.location.href = "index.html";
		           				}else{
		           					sweet.auto(result.message);
		           				}
		           			},
		           			error : function(result){
		           				sweet.auto("网络错误!");
		           			}
		           		}); 
          		}
              }
        </script>

	</body>
</html>